package org.bbsoft.catchme.model.entities;

import java.util.Calendar;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

@Entity
@Table(name = "EVENTS")
public class Event {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "EVENT_ID", nullable = false)
	private Long id;

	/** I used calendar because it is locale-sensitive */
	/** The start time of an event */
	@Column(name = "START", nullable = false)
	@Basic(optional = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Calendar start;

	/** The end time of an event */
	@Column(name = "END", nullable = false)
	@Basic(optional = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Calendar end;

	/** The location of the event */
	@Embedded
	@NotNull
	private Location location;

	/** The user who created the event */
	@ManyToOne(optional = false)
	@JoinColumn(nullable = false, name = "OWNER", referencedColumnName = "USER_ID")
	private User owner;

	/** The users who are invited to the event */
	@ManyToMany
	@JoinTable(name = "EVENTS_INVITED_USERS", joinColumns = { @JoinColumn(name = "EVENT_ID", referencedColumnName = "EVENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID") })
	private List<User> invitedUsers;

	/** The users who already accepted the event */
	@ManyToMany
	@JoinTable(name = "EVENTS_ACCEPTING_USERS", joinColumns = { @JoinColumn(name = "EVENT_ID", referencedColumnName = "EVENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID") })
	private List<User> acceptingUsers;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Calendar getStart() {
		return start;
	}

	public void setStart(Calendar start) {
		this.start = start;
	}

	public Calendar getEnd() {
		return end;
	}

	public void setEnd(Calendar end) {
		this.end = end;
	}

	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	public List<User> getInvitedUsers() {
		return invitedUsers;
	}

	public void setInvitedUsers(List<User> invitedUsers) {
		this.invitedUsers = invitedUsers;
	}

	public List<User> getAcceptingUsers() {
		return acceptingUsers;
	}

	public void setAcceptingUsers(List<User> acceptingUsers) {
		this.acceptingUsers = acceptingUsers;
	}

}
